<?php

namespace app\admin\model;

use think\Model;

class Users extends Model{

    private $groups = [
        '1' => '超级管理员',
        '2' => '管理员',
        '3' => '普通用户',
        '4' => '未验证用户'
    ];

    /**
     * 登录模块
     */
    public function Login($data){
        $map = [
            'username' => $data['username'],
            'password' => md5($data['password']),
        ];

        $res = $this->field('password',true)->where($map)->find();

        if($res){
            $groups = $this->groups;
            $res['ngroup'] = $groups[$res['group']];
            return $res;
        }else{
            return FALSE;
        }
    }

    /**
     * 更新登录时间
     */
    public function updateTime($id){
        $map = ['id' => $id];
        $data = [
            'login_time' => $_SERVER['REQUEST_TIME'],
            'login_ip' => $_SERVER['REMOTE_ADDR']
        ];

        return $this->where($map)->setField($data);
    }
}